
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main()
    {
        int pipefd[2];
        char *arg[] = {"head","-c", "100", "/proc/cpuinfo", NULL};//arg for execve head
        char *arg2[] = {"wc", NULL};//arg for wc
        char *arg3[] = {"cat", NULL};//arg for cat

        if( pipe(pipefd)==0 )
            {
                if( fork()==0 )
                    {
                        printf("Child is running.\n");
                        close(1);
                        printf("Child close fd[1].\n"); //print to where?
                        dup2(pipefd[1],1); //dup fd[1] to pipefd[1]
                        printf("Child dup fd[1] to pipefd[1].\n");
                        close(pipefd[0]);    
                        printf("Child close pipefd[0].\n"); 
                        execvp(arg[0],arg);
                        
                    }
                else
                    {
                    	printf("parent is running.\n");
                        close(0);
                        printf("parent close fd[0].\n");
                        dup2(pipefd[0],0);
                        printf("parent dup fd[0] to pipefd[0].\n");
                        close(pipefd[1]);
                        printf("parent close pipefd[1].\n"); 
                        execvp(arg3[0],arg3);
                      //    execvp(arg2[0],arg2);

                        
                    }
            }
        return 0;
        
    }

